/*
  S.M.A.C.K - An operating system kernel
  Copyright (C) 2010,2011 Mattias Holm and Kristian Rietveld
  For licensing and a full list of authors of the kernel, see the files
  COPYING and AUTHORS.
*/
#ifndef KERNEL__INTERRUPT_H
#define KERNEL__INTERRUPT_H

#include <stdint.h>

/* The following functions are to be implemented by the target arch */
#define N_IRQS 96 /* FIXME: must be in arch-specific header */

void hw_interrupt_init(void);

void disable_interrupts(void);
void disable_fast_interrupts(void);

void enable_interrupts(void);
void enable_fast_interrupts(void);

uint32_t save_flags(void);
void restore_flags(uint32_t flags);

void unmask_interrupt(unsigned int irq);
void mask_interrupt(unsigned int irq);

/*
  Main top level interrupt handler called by the IRQ assembly routines, this
  must be implemented by the target arch. The procedure should determine the
  interrupt cause and dispatch to the correct handler.
 */
void interrupt(void);


/* The following functions are generic */
typedef void (* irq_handler_func_t) (void *data);

void interrupt_init(void);
void interrupt_call_handler(uint32_t irq);
void interrupt_register_irq_handler(uint32_t            irq,
                                    irq_handler_func_t  func,
                                    void               *func_data);
void interrupt_deregister_irq_handler(uint32_t            irq,
                                      irq_handler_func_t  func,
                                      void               *func_data);

#endif /* !KERNEL__INTERRUPT_H */
